package com.zs.admin.controller.wisdbook;

import com.zs.admin.aop.Log;
import com.zs.admin.service.wisdbook.IWisdbookResourceService;
import com.zs.admin.validate.wisdbook.WisdbookResourceCreateValidate;
import com.zs.admin.validate.wisdbook.WisdbookResourceSearchValidate;
import com.zs.admin.validate.wisdbook.WisdbookResourceUpdateValidate;
import com.zs.admin.validate.commons.IdValidate;
import com.zs.admin.validate.commons.PageValidate;
import com.zs.admin.vo.wisdbook.WisdbookResourceDetailVo;
import com.zs.admin.vo.wisdbook.WisdbookResourceListedVo;
import com.zs.common.core.AjaxResult;
import com.zs.common.core.PageResult;
import com.zs.common.entity.wisdbook.WisdbookResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/wisdbook/resource")
@Api(tags = "资源管理")
public class WisdbookResourceController {

    @Resource
    IWisdbookResourceService iWisdbookResourceService;

    @PostMapping("/list")
    @ApiOperation(value="资源列表")
    public AjaxResult<PageResult<WisdbookResourceListedVo>> list(@Validated PageValidate pageValidate, @Validated @RequestBody WisdbookResourceSearchValidate searchValidate) {
        PageResult<WisdbookResourceListedVo> list = iWisdbookResourceService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @PostMapping("/detail")
    @ApiOperation(value="资源详情")
    public AjaxResult<WisdbookResourceDetailVo> detail(@Validated @RequestBody IdValidate idValidate) {
        WisdbookResourceDetailVo detail = iWisdbookResourceService.detail(idValidate.getId());
        return AjaxResult.success(detail);
    }

    @Log(title = "资源新增")
    @PostMapping("/add")
    @ApiOperation(value="资源新增")
    public AjaxResult<WisdbookResource> add(@Validated @RequestBody WisdbookResourceCreateValidate createValidate) {
        WisdbookResource resource = iWisdbookResourceService.add(createValidate);
        return AjaxResult.success(resource);
    }

    @Log(title = "资源编辑")
    @PostMapping("/edit")
    @ApiOperation(value="资源编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody WisdbookResourceUpdateValidate updateValidate) {
        iWisdbookResourceService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "资源删除")
    @PostMapping("/del")
    @ApiOperation(value="资源删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iWisdbookResourceService.del(idValidate.getId());
        return AjaxResult.success();
    }

}